<template>
  <div style="background-color: #f8f8f8">
    <myNavbar title="团长统计"></myNavbar>
    <div class="coupon_choose">
      <div class="coupon_choose-list" @click="swichNav">
        <text  :class="[currentTab==1?'coupon_choose_title':'coupon_choose_title_no']">进行中</text>
        <text :class="[currentTab==1?'coupon_choose_line_no':'']"></text>
      </div>
      <div class="coupon_choose-list"  @click="swichNavagin">
        <text  :class="[currentTab==4?'coupon_choose_title':'coupon_choose_title_no']">已完成</text>
        <text  :class="[currentTab==4?'coupon_choose_line_no':'']"></text>
      </div>
    </div>
    <div>
      <scroller class="groupCard_content" scroll-direction='horizontal'>
        <div class="groupCard_item" v-for="(item,index) in groupBuyName" @click="nameclick(item)">
          <text :class="[item.id==clickId?'groupCard_item_text':'groupCard_item_text_two']">{{item.name}}</text>
          <div :class="[item.id==clickId?'groupCard_item_text_div':'']"></div>
        </div>
      </scroller>
    </div>
    <list>
      <refresh class="refresh" @refresh="onrefresh" @pullingdown="onpullingdown" :display="refreshing ? 'show' : 'hide'">
        <text class="indicator-text">{{refreshTitle}}</text>
      </refresh>
      <cell>
        <div v-if="detailedList.length > 0">
          <div class="saveCard-bottom pd-L20 pd-R20">
            <div class="detailed-content" >
              <div class="detailed-box-content">
                <div style="display:flex; justify-content: space-around;flex-direction: row;">
                  <div style="display:flex;flex-direction: row">
                    <div class="detailed-title">
                      <text class="detailed-date" style="font-size: 32px">日期</text>
                    </div>
                  </div>
                  <div class="price-content">
                    <div style="width:190px;display:flex;  align-items: flex-end;justify-content: flex-end;padding-right: 20px">
                      <text class="yue" style="font-size: 32px;">单数</text>
                    </div>
                  </div>
                </div>
              </div>
              <gourp-order v-for="(item,index) in detailedList"  :orderData="item" @loadList='toOrderManager(item)'></gourp-order>
              <div class="detailed-box-content-bottom" @click="toOrderManager(item)">
                <div style="display:flex; justify-content: space-around;flex-direction: row;">
                  <div style="display:flex;flex-direction: row">
                    <div class="detailed-title">
                      <text class="detailed-date" style="font-size: 32px">合计</text>
                    </div>
                  </div>
                  <div class="price-content">
                    <div style="width:190px;display:flex;flex-direction: row;align-items: center;justify-content: flex-end;">
                      <text class="yue" style="font-size: 32px">{{total}}</text>
<!--                      <text class="mine-order-icon">&#xe65e;</text>-->
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </cell>
      <cell style="flex: 1;">
        <noData v-if="detailedList.length == 0" noDataText="您还没有相关的订单"></noData>
      </cell>
      <loading class="loading" v-if="detailedList.length >= 10" @loading="onloading" :display="loadinging ? 'show' : 'hide'">
        <text class="indicator-text">加载中...</text>
      </loading>
    </list>


  </div>

</template>
<script>
import gourpOrder from '../../../components/groupOrder/indexStatistics'
import myNavbar from "../../../components/myNavbar/myNavbar.vue";
import { list } from '@/api/point'
import { list as groupBuyList } from '../../../api/groupBuy'
import {statistics} from '@/api/groupOrder'
import noData from '../../../components/noData/noData.vue'

export default {
  data(){
    return{
      refreshTitle:'释放刷新页面...',
      currentTab:1,
      showDetail: false,
      scrollData: [], //记录要滚动的数据
      loadinging: false,
      pageNum: 1,
      pageSize: 10,
      detailedList: [],
      total:"0",
      groupBuyName:[],
      clickId:"",
      item:{}
    }
  },
  components: { myNavbar,noData,gourpOrder},
  mounted(){
    this.loadGroupBuy()
  },
  methods:{
    onpullingdown(event) {
      this.refreshTitle = '释放刷新页面...'
    },
    onrefresh(event) {
      this.refreshing = true
      this.refreshTitle = '加载中...'
      setTimeout(() => {
        this.pageNum=1
        this.refreshing = false
        // this.loadList()
        this.getdata()
      }, 1000)
    },
    nameclick(data){
      this.pageNum=1
      this.clickId=data.id
      this.getdata()
    },
    swichNav(){
      this.pageNum=1
      this.currentTab=1
      this.getdata()
    },
    swichNavagin(){
      this.pageNum=1
      this.currentTab=4
      this.getdata()
    },
    loadGroupBuy(){
      var _this = this
      groupBuyList({mchId:_this.getGlobalData().mchId,isShow:false,type:2}).then(res=>{
        _this.groupBuyName= res.data.data
        if (_this.groupBuyName.length>0) {
          _this.clickId = this.groupBuyName[0].id;
          _this.getdata()
        }
      })
    },
    toOrderManager(item){
      eeui.openPage({
        url: 'root://pages/member/groupbuy/orderManager.js',
        statusBarType: 'immersion',
        statusBarStyle: false,
        params: item
      }, result => {
        if (result.status == 'stop') {
        }
      });
    },
    getdata(){
      this.loadinging = true;
      if (this.pageNum == 1) {
        this.detailedList = []
      }
      console.log(this.pageSize)
      console.log(this.pageNum)
      statistics({
        pageSize: this.pageSize,
        pageNum: this.pageNum,
        orderStatus:this.currentTab,allChild:true,groupBuyId:this.clickId
      }).then(res=>{
        res.data.statisticsList.data.forEach(item => {
          this.detailedList.push(item)
        })
        this.total =res.data.summary
        if (this.detailedList.length>0){
          this.showDetail = true;
        }
        eeui.loadingClose();
        this.loadinging = false;
      })
    },
    // 触底加载
    onloading() {
      if (this.loadinging == false) {
        this.pageNum += 1;
        // modal.toast({ message: '加载中', duration: 1 });
        eeui.loading();
        this.getdata();
      }
    },
    formatDate2Time(val) {
      let date = new Date(val);
      let y = date.getFullYear();
      let MM = date.getMonth() + 1;
      MM = MM < 10 ? ('0' + MM) : MM;
      let d = date.getDate();
      d = d < 10 ? ('0' + d) : d;
      let h = date.getHours();
      h = h < 10 ? ('0' + h) : h;
      let m = date.getMinutes();
      m = m < 10 ? ('0' + m) : m;
      let s = date.getSeconds();
      s = s < 10 ? ('0' + s) : s;
      // return y + '-' + MM + '-' + d + " " + h + ":" + m + ":" + s;
      return y + '-' + MM + '-' + d;

    },
    loadlist() {
      if (this.pageNum == 1) {
        this.detailedList = []
      }
      list({
        pageSize: this.pageSize,
        pageNum: this.pageNum
      }).then(res => {
        res.data.data.forEach(item => {
          item.createDate = this.formatDate2Time(item.createDate)
          item.thumbnail = 'http://cdn.rzico.com/v4.0/wallet-consumption.png'
          this.data.detailedList.push(item)
        })
      })
    },
    // 上拉加载更多
    onPullDownRefresh() {
      wx.showNavigationBarLoading()
      this.data.pageNum = 1
      setTimeout(() => {
        wx.hideNavigationBarLoading()
        this.loadList()
        wx.stopPullDownRefresh()
      }, 1000);
    },
    onReachBottom() {
      this.data.pageNum += 1
      this.loadList()
    },
  }

}
</script>
<style>
page {
  background: rgb(248, 248, 248);
}
.coupon_choose {
  /* position: fixed; */
  width: 750px;
  text-align: center;
  line-height: 80px;
  padding-left: 26px;
  padding-right: 26px;
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  justify-content: center;
  height: 76px;
  background-color: #fff;
}
.coupon_choose-list {
  width: 300px;
  height: 70px;
  display: flex;
  flex-direction: column;
  align-items:center;
  justify-content: center;
}
.coupon_choose_title {
  font-size: 32px;
  font-weight: 500;
  padding-bottom: 5px;
  color: rgba(215, 38, 28, 1);
  margin-bottom: 5px;

}
.coupon_choose_title_no {
  /*font-size: 28px;*/
  font-size: 32px;
  font-weight: 500;
  padding-bottom: 5px;
  color: rgba(102, 102, 102, 1);
}
.coupon_choose_line {
  width: 34px;
  height: 6px;
}
.coupon_choose_line_no {
  background-color: rgb(231, 91, 83);
  height: 4px;
  width: 50px;
}
.vein {
  position: absolute;
  width: 100%;
}

.rule-content {
  z-index: 200;
  position: fixed;
  background-color: rgba(0, 0, 0, 0.5);
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
}

.rule-dio {
  display: flex;
  padding-top: 20px;
  flex-direction: column;
  align-items: center;
  height: 350px;
  width: 710px;
  background-color: white;
  border-radius: 16px;
}
.rule-text{
  height: 70px;
  width: 350px;
  display: flex;
  flex-direction: row;
  align-items: center;
  /* justify-content: center; */
}
.yue{
  /*font-size: 24px;*/
  font-size: 32px;
  font-family: PingFangSC;
  font-weight: 400;
  color: #1a1a1e;
  opacity: 0.3;
}
.rule-click {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  margin-top: 20px;
  height: 60px;
  width: 170px;
  background: linear-gradient(to right, #474747, #474747);
  color: #b19e81;
  border-radius: 14px;
}

.rule-title {
  color: #b19e81;

}
.deposit {
  width: 750px;
  height: 600px;
  background-image: linear-gradient(to bottom, #c2c2c2, #f8f8f8);

}
.price-content{
  /*display: flex;*/
  /*flex-direction: column;*/
  /*justify-content: space-between;*/
  /*height: 100%;*/
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.total-deposit {
  height: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.total-deposit-head {
  width: 655px;
  padding-top: 30px;
  height: 105px;
  background: linear-gradient(to right, #f7dec5, #f0d0a7);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  padding-left: 20px;
  padding-right: 20px;
}

.total-deposit-bottom {
  height: 120px;
  background-color: white;
  width: 710px;
  padding-top: 20px;
  padding-left: 20px;
  padding-right: 20px;
}

.aaaa {
  width: 750px;
  height: 91px;
}

.total-deposit-money {
  width: 695px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.botton-deposit {
  padding-top: 20px;
  /* height: 260px; */
  background-color: white;
  padding: 20px;
  /* padding-bottom: 20px; */
}

.botton-deposit-title-content {
  height: 40px;
  width: 143px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.vertical {
  margin-top: 10px;
  height: 30px;
  width: 10px;
  background: linear-gradient(to bottom, #FFFFF0, #FFD39B);
}

.botton-deposit-title {
  font-size: 30px;
}

.botton-deposit-botton-content {
  display: flex;
  flex-direction: row;
  justify-content: space-around;

}

.title-button {
  margin-top: 10px;
  font-size: 28px;

}

.button-content {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  /* margin-top: 40px; */
  width: 200px;

}

.button {
  height: 120px;
  width: 120px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: linear-gradient(to right, #f7dec5, #f0d0a7);
}

.title {
  margin-top: 10px;
  font-size: 28px;
  margin-left: 20px;
}

.detailed-content {
  padding-bottom: 20px;
  padding-top: 20px;
  margin-top: 30px;
  margin-left: 20px;
  margin-right: 20px;
  overflow-y: auto;
  /*background-color: yellow;*/
  background-color:#ffffff;
  border-radius:10px;
}

.detailed-title-content {
  width: 710px;
  padding-left: 20px;
  display: flex;
  flex-direction: row;
  margin-bottom: 40px;
  overflow: hidden;

}

.detailed-box-content {
  padding-right: 35px;
  padding-left: 35px;
  align-content: center;
  justify-content: space-between;
  /*height: 140px;*/
}
.detailed-box-content-bottom{
  position: fixed;
  bottom: 0px;
  left:35px;
  padding-right: 35px;
  padding-left: 35px;
  align-content: center;
  justify-content: space-between;
  background-color: white;
  border-top-right-radius:15px;
  border-top-left-radius: 15px;

}
.detailed-box-bottom{
  position: fixed;
  bottom: 0;
  right: 0;
}


.detailed-title {
  margin-left: 20px;
  width: 400px;
  display: flex;
  flex-direction: column;

}
.aaaaa{
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 400px;
  max-height: 92px;
}
.detailed-name {
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  text-overflow: ellipsis;
  justify-content: space-between;
  font-size: 25px;
}

.detailed-date {
  margin-top: 10px;
  /*font-size: 25px;*/
  font-size: 32px;
  color: #808080;
}

.price {
  float: right;
  color: #FF6347;
  font-weight: 700;
  font-size: 27px;
}
.reducePrice{
  float: right;
  color: black;
  font-weight: 700;
  font-size: 27px;
}
.invitation-button {

  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  background-color: #333333;
  color: #ffffde;
  font-size: 30px;
  border-radius: 20px;
}

.header {
  height: 146px;
  padding-right: 47px;
  padding-left: 30px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.header-info {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  margin-bottom: 20px;
}


.rule {
  z-index: 100;
  width: 170px;
  height: 50px;
  border-radius: 20px;
  opacity: 0.8;
  display: flex;
  flex-direction: row;
  justify-content:space-evenly;
  align-items: center;
  font-size: 25px;
}

.rule-circular {
  height: 30px;
  width: 30px;
  border: 4px solid;
  /*color: black;*/
  border-radius: 50px;
  font-size: 20px;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
}

.isMaskCanvas {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.cancelCanvasBotton {
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  color: white;
  font-size: 40px;
  width: 440px;
  margin-bottom: 20px;
}


.poste_content {
  width: 440px;
  /* margin: auto; */
  overflow: hidden;
  /* margin-top: 200px; */
  /* background-color: #fff; */
  /* position: absolute;
  top: 0; */
  z-index: 9999;
  border-radius: 16px;
}
.canvasBotton {
  border: 2px solid white;
  padding: 10px 100px;
  border-radius: 100px;
  margin-top: 40px;
}
.canvasBottonTitle {
  font-size: 28px;
  color: white;
}
.indicator-text {
  color: #888888;
  font-size: 22px;
  text-align: center;
  padding-top: 20px;
}
.detailed-box-wrap{
  /*border-top-width: 1px;*/
  /*borde-top-color: lightgray;*/
  /*border-top-style: solid;*/
  border-bottom-style: solid;
  border-bottom-color: #E8E8E8;
  border-bottom-width: 2px;
}

.groupCard_content{
  width: 710px;
  height: 80px;
  display: flex;
  flex-direction: row;
}
.groupCard_item{
  height: 80px;
  align-items: center;
  margin-left: 20px;
  margin-right: 30px;
  border-radius: 16px;
}
.groupCard_item_text{
  font-size:32px;
  font-weight: bold;
  color:rgb(231, 91, 83);;
  margin-top:20px;
  text-align:center;
}
.groupCard_item_text_two{
  font-size:28px;
  /* font-weight: bold; */
  color:black;
  margin-top:20px;
  text-align:center;
}
.groupCard_item_text_div{
  width: 70px;
  background-color:rgb(231, 91, 83);;
  height: 7px;
  /*margin-left:20px;*/
  margin-top: 5px;
}
.mine-order-icon {
  margin-left: 10px;
  font-family: iconfont2;
  font-size: 32px;
  /*color: #DFBB85;*/
  color: #808080;

}
</style>
